<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="收货" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doGather(id,favCost){
		var url="/cooper/GatherBillNew.ihtm?cooper_bill_id="+id;
		ShowIframe("收货",url,1024,500,"doGatherCallBack("+favCost+")",900,600);
	}
	function doGatherCallBack(favCost){
		if(popRetVal!=null){
			var url=getProgramLocation()+"&current_page=${qr.pageIndex}";
			ShowConfirm('确认框','现在打印收货单？',340,80,"doGatherCallBackPriExt('"+url+"',"+popRetVal+","+favCost+")");
		}
	}
	function doGatherCallBackPriExt(url,id,favCost){
		if(popRetVal!=null){
			if(favCost==0){
				ShowConfirm('确认框','收货单打印金额？',340,80,"doGatherCallBackCostExt('"+url+"',"+id+")");
			}else{
				window.location=url+"&print_id="+id;
			}
		}else{
			window.location=url;
		}
	}
	function doGatherCallBackCostExt(url,id){
		var printCost="0";
		if(popRetVal!=null){
			printCost="1";
		}
		var url=url+"&print_id="+id+"&print_cost="+printCost;
		window.location=url;
	}
	function getProgramLocation(){
		var searchKey=encodeURIComponent("${searchKey}");
		return "/cooper/CooperBillListForGather.ihtm?search_key="+searchKey+"&type=${type}&ts_id=${tsId}";
	}
	function doSearch(){
		var type=document.getElementById("type").value;
		var tsId=document.getElementById("ts_id").value;
		var searchKey=encodeURIComponent(document.getElementById("search_key").value.trim());
		window.location="/cooper/CooperBillListForGather.ihtm?search_key="+searchKey+"&type="+type+"&ts_id="+tsId;
	}
	function doGo(pageIndex){
		window.location=getProgramLocation()+"&current_page="+pageIndex;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function DoubleClick(it){
		var ob_arr = document.getElementsByName("query_checkbox");
		var str="";
		var favCost="0";
		if(ob_arr.length>=it.getAttribute("index")){
			str=ob_arr[it.getAttribute("index")-1].value;
			favCost = ob_arr[it.getAttribute("index")-1].getAttribute("fav_cost");
		}
		if(str==""){
			return;
		}
		doGather(str,favCost-0);
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		//Window_Onload();
		document.getElementById("search_key").focus();
	}
	function checkSearchKey(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function doPrint(id){
		showWin(900,600,"/cooper/CooperBillPrint.ihtm?id="+id);
	}
	function doSms(estName,estId,billContent){
		var url="/sms/SmsSendForm.ihtm?est_id_str="+estId;
		if(estName!=""){
			if(billContent!=null && billContent!=""){
				billContent="("+billContent+")";
			}
			var content=estName+"：订单"+billContent+"什么时候可以完工？";
			url=url+"&content="+encodeURIComponent(content);
		}
		showWin(900,500,url);
	}
	function doMutiSms(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var str="";
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				if(str!=""){
					str=str+";";
				}
				str = str+ob_arr[i].getAttribute("cooperator_id");
			}
		}
		if(str!=""){
			doSms("",str,"");
		}else{
			ShowAlert('提示框','请选择要发短信的外协商',200,100);
		}
	}
	function doMutiGather(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var str="";
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				if(str!=""){
					str=str+";";
				}
				str = str+ob_arr[i].value;
			}
		}
		if(str!=""){
			ShowConfirm('确认框','确定将选择的外协单直接设置为已收完货状态吗？',340,80,"doMutiGatherCallBack('"+str+"')");
		}else{
			ShowAlert('提示框','请选择要收货的外协单',200,100);
		}
	}
	function doMutiGatherCallBack(str){
		if(popRetVal!=null){
			var url="/cooper/GatherBillBatchNew.ihtm?coo_id_str="+str;
			ShowIframe("收货",url,200,200,"refreshWin()");
		}
	}
	function refreshWin(){
		if(popRetVal!=null){
			window.location=getProgramLocation()+"&current_page=${qr.pageIndex}";
		}
	}
	function showSmsSubscribe(){
		<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';SMS_SUBS;')!=-1}">
		showWin(520,640,'/sms/SmsSubscribe.ihtm');
		</c:if>
		<c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';SMS_SUBS;')==-1}">
		ShowAlert('提示框','对不起，您还没有短信订阅设置权限。',200,100);
		</c:if>
	}
	function doPrintCallBack(){
		var printId="${printId}";
		var printCost="${printCost}";
		if(printId!=null && printId!=""){
			showWin(900,600,"/cooper/GatherBillPrint.ihtm?id="+printId+"&print_cost="+printCost);
		}
	}
	function showRelBill(id,code){
		showWin(900,600,"/cooper/CooperRelBillList.ihtm?id="+id+"&code="+code);
	}
</script>
</head>
<c:set var="smsFlag" value="0" />
<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';SMS_SEND_SIMP;')!=-1}"><c:set var="smsFlag" value="1" /></c:if>
<body oncontextmenu="return false" onLoad="doInit();doPrintCallBack();" class="sheet" style="text-align:center;">
<div class="sheet-main" style="width:860px;text-align:left;margin:auto;">
  <div class="sheet-top">
    <div class="content">
      <h2>收货</h2>
      <p>根据外协单的交货日期、收货状态进行分类查询，生成收货单。<span style="color:blue">蓝色</span>表示外协单已开过收货单</p>
    </div>
  </div>
  <div class="sheet-list">
    <div class="search-business">
      <div class="content">
        <table width="748">
          <tbody>
            <tr>
				<td align="right">
				  <select name='ts_id' id="ts_id">
					<option value="0">==请选择账套==</option>
					<c:forEach var="item" items="${tsList}">
					<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option>
					</c:forEach>
		  		  </select>
		  		  <select name="type" id="type">
				  	<option value="">==请选择==</option>
					<option value="UN_GATHER" <c:if test="${type=='UN_GATHER'}">selected</c:if>>全部未收货</option>
					<option value="UN_GATH_TIMEOUT" <c:if test="${type=='UN_GATH_TIMEOUT'}">selected</c:if>>超期未收货</option>
					<option value="PART_GATH" <c:if test="${type=='PART_GATH'}">selected</c:if>>部分收货</option>
				  </select>
		  		  
				  <input type="text" class="TextBox" id="search_key" name="search_key" onKeyUp="checkSearchKey();" style="width:80px" value="${searchKey}" title="以外协单位名称、外协单位拼音字头、摘要、外协单号进行模糊查询">
				  <input type="button" class="buttom search-but" value=" 查 询" onClick="doSearch();" title="以外协单位名称、外协单位拼音字头、摘要、外协单号进行模糊查询">
				  <input type="button" class="buttom search-add" value=" 收 货" onClick="doMutiGather();" title="直接将已选中的外协单设置为已收完货状态">
				  <input type="button" value=" 短 信" onClick="doMutiSms();" id="sSmsButton" name="sSmsButton" class="buttom search-sms" <c:if test="${smsFlag!='1'}">disabled="true"</c:if>>
			  </td>
            </tr>    
           </tbody>      
        </table>
      </div>
	  <%@include file="../inc/AlertMsg.jsp"%>
      <div class="table-list">
        <table width="100%">      
 					<tr >
						<th width="14"><input type="checkbox" onClick="javascript:checkall(this);"></th>
						<th  width="13%">单号</th>
						<th  width="9%">外协日期</th>
						<th  width="19%">外协单位</th>
						<th  width="15%">摘要</th>
						<th  width="9%">交货日期</th>
						<th  width="15%">交货要求</th>
						<th  width="8%">业务员</th>
						<th  width="12%">操作</th>
					</tr>
				<c:forEach var="item" items="${qr.list}" varStatus="i">
					<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
					<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
					<c:set var="defaultFontColor" value="black" />
					<c:if test="${item[2]=='Y'}"><c:set var="defaultFontColor" value="blue" /></c:if>
					<tr class="${trClass}" index="${i.index+1}" style="cursor:pointer;color:${defaultFontColor}" defaultFontColor="${defaultFontColor}" ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this,true)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
						<td><input type="checkbox" onClick="javascript:ClickCheck(this,true);" name='query_checkbox' value="${item[0].id}" fav_cost="${item[0].favCost}" cooperator_id="${item[0].cooperatorId}"></td>
						<td>${item[0].billCode}</td>
						<td><fmt:formatDate value="${item[0].cooperDate}" pattern="yyyy-MM-dd"/></td>
						<td>${item[1]}<c:if test="${item[0].linkman!=null && item[0].linkman!=''}">(${item[0].linkman})</c:if></td>
						<td>${item[0].content}</td>
						<td>
							<c:if test="${item[0].gatherDate!=null}">
							<fmt:formatDate value="${item[0].gatherDate}" pattern="yyyy-MM-dd"/>
							</c:if>
						</td>
						<td>${item[0].gatherRequire}</td>
						<td>${item[0].managerName}</td>
						<td>
							<a href="javascript:showRelBill('${item[0].id}','${item[0].billCode}');">查看</a>
							<a href="#" onClick="doGather('${item[0].id}',${item[0].favCost});">收货</a>
							<c:if test="${smsFlag=='1'}"><a href="javascript:doSms('<c:out value="${item[1]}" />','${item[0].cooperatorId}','<c:out value="${item[0].content}" />');"></c:if>短信<c:if test="${smsFlag=='1'}"></a></c:if>
						</td>
					</tr>
				</c:forEach>
			</table>
			<%@include file="../inc/Pages.jsp"%>
      </div>     
    </div>
  </div>
</div>
</body>
</html>

